// ################### Constants for hex file organisation ####################

#define REV_ADDRESS 3996	 //----- location of Version number in FW hex code, changed to fit hardware
#define FWA_REV_ADDRESS 4060 //----- acam code address location
#define FWA_ADDRESS 4000	 //----- starts for zero file
#define OPEN_REV_ADDR 1082	 //---- location of Version number in FW hex code: PROTECT_LIM-6
#define PROTECT_LIM 1088	 //---- location of the start address of protected memory

// start addresses for main internal routines of acam firmware, not included in open firmware file// change of A1.A2.11.01
#define MK_PP 0x0fcd					  // 4045	// Post processing
#define MK_EH 0x0fd0					  // 4048	// Error flag handling
#define MK_CHK_AND_RESUME 0x0fd3		  // 4051	// Operation reliability
#define MK_CHK_AND_RESUME_NORECALL 0x0fd6 // 4054 // to be used if hourly recall is undesired

// #############      Naming conventions    #######################
//  RAM_.... general RAM addresses  0x00 - 0xAF
//  RAM_R_... RAM Addresses and constants used in ROM Routines
//  RAM_VXX_... Temporary RAM variable addresses, same number XX indicates same address
//  FDB_... Firmware data buffer, part of the RAM temporarily used by the front-end (0x80 - 0x9B)

// FWD_... Firmware data, user configuration input 0x100 - 0x17F// 0x16C - 0x17F used for input of config registers
// FWD_R_... Firmware data registers used by ROM routines
// CR_... Configuration registers addresses
// SHR_... System handling register addresses
// SRR_... Status and REsults register addresses
// SR_... Special register actions (commands)

// BNR_... Bit number within a data word

// #############      Memory organisation      #####################
//  NOTE: Adresses below 3F are more suitable for frequent use becasue of their fast access
//  0x00 - 0x24: Results and variables that need storage for more than one cycle
//   0x00 - 0x08 Flow results
//   0x09 - 0x1F internal variables
//   0x20 - 0x24 Temperature measurement results

// 0x25 - 0x28: Status Control: Firmware Status, Error Flags and Counters

// 0x29 - 0x33: Firmware temporary variables (can be overwritten after a normal cycle end)

// 0x34: amplitude offset variable for hardware check

// 0x35 - 0x4C// Free RAM

// 0x50 - 0x51: optional storage of negative volume flow - requires also temporary use of FWD_R_FLOW_VOLUME_FRACTION and FWD_R_FLOW_VOLUME_INT
// 0x52 - 0x55: optional copies of volume flow for redundant storage
// 0x56: Flag register for remote communication (Copy of recent SRR_FEP_STF)

// 0x57 - 0x5F: Status Control and I2C
//  0x57        Debug register for switching off parts of the firmware
//  0x58		   I2C communication: EEPROM Address
//  0x59 - 0x5C Error and cycle Counters
//  0x5D - 0x5F Clocks

// 0x60 - 0x6F: 16 stage filters (need storage for more than one cycle)
// 0x70 - 0x7F: double 8 stage filters (need storage for more than one cycle)
// 0x80 - 0x9B: Frond end data buffer (TDC data output, may be overwritten as soon as data was processed)
// 0x9C - 0xAF: Firmware temporary variables (can be overwritten after a normal cycle end), many used by ROM code
//  0xA1 - 0xAF: Temporary variables used by ROM code in initialisation

// Permanent parameters and Results, not to be overwritten
// #############################################################################
//----------------------------- Flow Calculation : RAM Results and variables ----(0x00x- 0x1F) -------------------------------------------
#define RAM_R_FLOW_VOLUME_INT 0x00		//---- Integer part of Total volume of water flow in Cubic meter   fd0
#define RAM_R_FLOW_VOLUME_FRACTION 0x01 //---- Fractional part of Total volume of water flow in Cubic meter  fd32
#define RAM_R_FLOW_LPH 0x02				//---- Calculated flow volume (l/h) with fd 16 without filtering
#define RAM_FILTERED_FLOW_LPH 0x03		//---- Filtered flow volume (l/h) with fd 16
#define RAM_R_THETA 0x04				//---- Calculated Temperature with 16 fd (°C)
#define RAM_SOUND_VEL 0x05				//---- Velocity of sound with 8 fd(m/s)
#define RAM_FLOW_SPEED 0x06				//---- Calculated speed of flow (m/s) with fd 16
#define RAM_R_TOF_DIFF 0x07				//---- TOF Difference
#define RAM_R_TOF_SUM 0x08				//---- TOF Sum
//-----------------------------------Flow Calculation: Intermediate results to be kept from former measurements or calibrations-----------
#define RAM_R_VOLUME_FACTOR 0x09	   //---- Fixed factor for multiplication during calculation of Flow Volume in Cubic meter
#define RAM_R_FLOW_SCALE_FACT 0x0A	   //---- Factor to scale the flow for the pulse interface
#define RAM_R_ZCD_FHL_U 0x0B		   //---- Copy of the User configuration for the ZCD_FHL_U bits
#define RAM_R_ZCD_FHL_D 0x0C		   //---- Copy of the User configuration for the ZCD_FHL_D bits
#define RAM_R_TC_LOW 0x0D			   //---- Lower end of the Temperature range calculated with given calibration points
#define RAM_R_TC_HIGH 0x0E			   //---- Higher end of the Temperature range calculated with given calibration points
#define RAM_FILTERED_FLOW 0x0F		   //---- Filtered-Scaled flow volume with fd 24 (Scaled with 2^n nearest to maximum allowed flow)
#define RAM_R_TOF_DIFF_FLT 0x10		   //---- Filtered TOF_DIFF from the rolling average filter
#define RAM_R_TOF_SUM_FLT 0x11		   //---- Filtered TOF_SUM from the rolling average filter
#define RAM_R_TOF_DIFF_LAST_VALID 0x12 //---- Last valid value of DIFF TOF
#define RAM_R_TOF_SUM_LAST_VALID 0x13  //---- Last valid value of SUM TOF
#define RAM_R_FLOW_LPH_ACCU 0x14	   //---- Accumulated value of flow over previous N cycles
#define RAM_ZERO_OS_THETA 0x15		   //---- ZERO_OFFSET after linear correction with temperature THETA
#define RAM_R_TOF_OFFSET 0x16		   //---- TOF Offset to be deducted from the TOF_ADD_ALL scaled with HS Calibration factor
#define RAM_R_F_OFFSET_HSC_TC2 0x17	   //---- F_OFFSET at TC2 corrected with HS Clock calibration factor
#define RAM_R_F_OFFSET_HSC_TC3 0x18	   //---- F_OFFSET at TC3 corrected with HS Clock calibration factor
#define RAM_R_F_OFFSET_HSC_TC4 0x19	   //---- F_OFFSET at TC4 corrected with HS Clock calibration factor
#define RAM_R_CFG_TOF_RATE 0x1A		   //---- TOF RATE value from original configuration
#define RAM_R_TOF_HIT_NO 0x1B		   //---- TOF Hit Number

//----------------- Amplitude measurement variables---------------------------------
#define RAM_R_AM_MIN_RAW 0x1C	//---- Calculated minimum amplitude raw value, used for checking signal quality
#define RAM_R_AMC_GRADIENT 0x1D //---- Gradient used for amplitude calculation
#define RAM_R_AMC_OFFSET 0x1E	//---- Offset used for amplitude calculation

//-----------start address for PWL table / temporary variable for shift operations
#define RAM_R_V1F_COEFF_ADR 0x1F //---- temporary Start adress of cal coefficients block
#define RAM_R_V1F_SHIFT 0x1F	 //---- Temporary variable for rapid shifting

// -----------------Results from Temperature Measurement----------------------------------
#define RAM_R_PTC_TEMPERATURE 0x20	  //---- Cold sensor temperature with 16 fd
#define RAM_R_PTH_TEMPERATURE 0x21	  //---- Hot sensor temperature with 16 fd
#define RAM_PTC_RES 0x22			  //---- Cold sensor resistance with 16 fd
#define RAM_R_PTH_RES 0x23			  //---- Hot sensor resistance with 16 fd
#define RAM_R_PT_INT_TEMPERATURE 0x24 //---- Internal sensor temperature with 16 fd

//------------------Firmware Status-----------------------------------
#define RAM_R_FW_STATUS 0x25	//--- Firmware Status
#define RAM_FLOW_COUNTER 0x26	//---- Global counter that counts the number of sample flow values evaluated
#define RAM_R_FW_ERR_FLAGS 0x27 //---- Error bits generated by evaluation in firmware
#define RAM_R_FHL_ERR_CTR 0x28	//---- Counter to count the number of cycles of wrong measurement// cleared for every correct measurement

// Temporary and local parameters and results in RAM cells, can be overwritten as soon as they fulfilled their local purpose
// #############################################################################
//------------------Parameters from flow calculation--------------------
#define RAM_V29_CORR_ZERO_OFFSET 0x29	 //---- Zero Offset corrected over temperature and DIFF TOF
#define RAM_R_V29_FLOW_LPH_OLDVAL 0x29	 //---- Backed up values in case of USM/AM Error ONLY
#define RAM_V2A_CONST_F 0x2A			 //---- Value calculated from F_SLOPE & F_OFFSET with THETA and HSC corrections
#define RAM_R_V2A_FLOW_THETA_OLDVAL 0x2A //---- Backed up values in case of USM/AM Error ONLY

//------------------Parameters from Temperature measurement----------------
#define RAM_R_V2B_PTC_TEMPERATURE_OLDVAL 0x2B	 //---- Backed up values in case of TM Error ONLY
#define RAM_V2B_PTC_TIME 0x2B					 //---- Time equivalent to the Cold sensor resistance with fd 16 (Back up value in case of TM error)
#define RAM_R_V2C_PTH_TEMPERATURE_OLDVAL 0x2C	 //---- Backed up values in case of TM Error ONLY
#define RAM_V2C_PTH_TIME 0x2C					 //---- Time equivalent to the Hot sensor resistance with fd 16 (Back up value in case of TM error)
#define RAM_R_V2D_PT_INT_TEMPERATURE_OLDVAL 0x2D //---- Backed up values in case of TM Error ONLY

//--------------------------- RAM used in 4 wire temperature measurement
#define RAM_V2D_PTR_TIME 0x2D	  //---- Time equivalent to the Reference resistance with fd 16
#define RAM_V2E_OFFSET_DELAY 0x2E //---- Offset to compensate for the Schmitt Trigger delay with fd 16
#define RAM_V2F_PTR_OFFSETR 0x2F  //---- Reference branch Offset Resistance with fd 16
//-----------------------------  Temperature measurement : RAM Variables for 2- or 4- Wire Mode----------------------------------------
#define RAM_V30_PTCU_OFFSETR 0x30 //---- Cold Upper Offset Resistance with fd 16
#define RAM_V31_PTHU_OFFSETR 0x31 //---- Hot Upper Offset Resistance with fd 16
#define RAM_V32_PTCL_OFFSETR 0x32 //---- Cold Lower Offset Resistance with fd 16
#define RAM_V33_PTHL_OFFSETR 0x33 //---- Hot Lower Offset Resistance with fd 16

//================== Temporarily used RAM Addresses used in filtering and for square root =====================================
#define RAM_R_V2E_SQRT_Y 0x2E	  //---- Temporary variable used to calculate the square root
#define RAM_R_V2F_SQRT_X 0x2F	  //---- Temporary variable to store X in square root calculation
#define RAM_R_V30_PREV_AVG 0x30	  //---- Temporary variable used in the rolling average filter (formerly input to the R.A. filter with the previous average result) change of A1.A1.22.01
#define RAM_R_V31_FILTER_2 0x31	  //---- Temporary variable used in the rolling average filter
#define RAM_R_V32_FILTER 0x32	  //---- Temporary variable used in the filter initializations
#define RAM_R_V33_FILTER_SUM 0x33 //---- Temporary variable used in the R.A. filter to store the sum during average calculation

//---------------------------- amplitude offset variable for hardware check// change of A1.A2.11.01
#define RAM_V34_AM_HW_OFFSET 0x34

// ############################    0x35 -    0x4C free user RAM

//---------------------------- optional: Maximum storage for average error counters FWD_ERROR_COUNT_21, .._43 // change of A1.A1.22.01
#define RAM_ERROR_COUNT_21 0x4D
#define RAM_ERROR_COUNT_43 0x4E

//---------------------------- optional flow and flow volume for negative flow// change of A1.A1.21.01
#define RAM_NEG_FLOW 0x4F
#define RAM_NEG_FLOW_VOLUME_INT 0x50
#define RAM_NEG_FLOW_VOLUME_FRACTION 0x51
//---------------------------- optional copies of flow volume for redundant storage// change of A1.A1.21.01
#define RAM_C1_FLOW_VOLUME_INT 0x52
#define RAM_C2_FLOW_VOLUME_INT 0x53
#define RAM_C1_FLOW_VOLUME_FRACTION 0x54
#define RAM_C2_FLOW_VOLUME_FRACTION 0x55

//---------------------------- Flag register for remote communication (Copy of recent SRR_FEP_STF)
#define RAM_FEP_STF 0x56

//------------------Parameters for I2C communication------------------
// #define RAM_V2F_EEPROM_ADDR 		0x58			//---- EEPROM Address for writing the data

//--------------- Status control variables / counters -------------------------------------------------------------------
#define RAM_LOW_AM_ERR_CTR 0x57 //---- Counter to count consecutive low am cases for empty pipe decision
#define RAM_TS_ERR_CTR 0x58		//---- Counter to count Task sequencer timeout errors // change of A1.A1.22.01
#define RAM_R_TM_ERR_CTR 0x59	//---- Counter to count the TM errors
#define RAM_R_USM_ERR_CTR 0x5A	//---- Counter to count the USM errors
#define RAM_R_AM_ERR_CTR 0x5B	//---- Counter to count the AM errors
#define RAM_CYCLE_COUNTER 0x5C	//---- Global counter counts from 0-15 and rolls over, increments every cycle

// ----------------Global variables: clocks --------------
#define RAM_R_HSC_SCALE_FACT 0x5D //---- HS Clock scaling factor  (8 integer bits + 24 fractional bits)
#define RAM_R_TDC_PERIOD 0x5E	  //---- TDC Period = (250 or 125 * 10^-9 * 2^32)// This variable considers HSC calibration// change of A1.A1.22.01
#define RAM_R_TDC_CLK 0x5F		  //---- Global variable : TDC clock = (4MHz = 0x003D0900 | 8MHz = 0x007A1200), devided by distance with flow// This variable considers HSC calibration// change of A1.A1.22.01

// Permanent parameters and results in RAM cells with alternative use
// #############################################################################

//------- RAM 0x60 - 0x6F for Rolling average filter (see at the end)--------------
//-----------------------------------------------------------------------------------------------------
//-- A median filter to filter the final flow value
//-- RAM addresses for Median filter -------
//-- Result is in RAM_FILTERED_FLOW
#define RAM_MEDIAN_0 0x66
#define RAM_MEDIAN_1 0x67
#define RAM_MEDIAN_2 0x68
#define RAM_MEDIAN_3 0x69
#define RAM_MEDIAN_4 0x6A
#define RAM_MEDIAN_5 0x6B
#define RAM_MEDIAN_6 0x6C
#define RAM_MEDIAN_7 0x6D
#define RAM_MEDIAN_8 0x6E
#define RAM_MEDIAN_9 0x6F
//-----------------------------------------------------------------------------------------------------
//-- A rolling average filter to filter the final flow value
//-- RAM addresses for Rolling average filter -------
// Result is in RAM_FILTERED_FLOW
#define RAM_R_ROLAVG_1 0x60
#define RAM_ROLAVG_2 0x61
#define RAM_ROLAVG_3 0x62
#define RAM_ROLAVG_4 0x63
#define RAM_ROLAVG_5 0x64
#define RAM_ROLAVG_6 0x65
#define RAM_ROLAVG_7 0x66
#define RAM_ROLAVG_8 0x67
#define RAM_ROLAVG_9 0x68
#define RAM_ROLAVG_10 0x69
#define RAM_ROLAVG_11 0x6A
#define RAM_ROLAVG_12 0x6B
#define RAM_ROLAVG_13 0x6C
#define RAM_ROLAVG_14 0x6D
#define RAM_ROLAVG_15 0x6E
#define RAM_ROLAVG_16 0x6F

//==============================================================================================================
// RAM Allocations for different kinds of filters  (0x70 - 0x7F)
// The different filters generally cannot be used simultaneously. Before using more than one, check the addresses
//---------------------------------------------------------------------------------------------------------------
// Two median filter of length 5 : One each for filtering TOF_UP and TOF_DOWN
// RAM Addresses for Median filters for UP and DOWN respectively
#define RAM_MEDIAN_U_0 0x70
#define RAM_MEDIAN_U_1 0x71
#define RAM_MEDIAN_U_2 0x72
#define RAM_MEDIAN_U_3 0x73
#define RAM_MEDIAN_U_4 0x74
#define RAM_TOF_UP 0x75 //---- Normalised TOF Up value after median filtering

#define RAM_MEDIAN_D_0 0x76
#define RAM_MEDIAN_D_1 0x77
#define RAM_MEDIAN_D_2 0x78
#define RAM_MEDIAN_D_3 0x79
#define RAM_MEDIAN_D_4 0x7A
#define RAM_TOF_DOWN 0x7B //---- Normalised TOF Down value after median filtering
//-----------------------------------------------------------------------------------------------------
//-- A rolling average filter of max. length 8 to filter the DIFF_TOF value
//-- RAM addresses for Rolling average filter -------
// Result is in RAM_ROLAVG_DIFTOF_FIL 0x77
#define RAM_ROLAVG_DIFTOF_1 0x70
#define RAM_ROLAVG_DIFTOF_2 0x71
#define RAM_ROLAVG_DIFTOF_3 0x72
#define RAM_ROLAVG_DIFTOF_4 0x73
#define RAM_ROLAVG_DIFTOF_5 0x74
#define RAM_ROLAVG_DIFTOF_6 0x75
#define RAM_ROLAVG_DIFTOF_7 0x76
#define RAM_ROLAVG_DIFTOF_FIL 0x77
//-----------------------------------------------------------------------------------------------------
//-- A rolling average filter of max. length 8 to filter the SUM_TOF value
//-- RAM addresses for Rolling average filter -------
// Result is in RAM_ROLAVG_SUMTOF_FIL 0x7F
#define RAM_ROLAVG_SUMTOF_1 0x78
#define RAM_ROLAVG_SUMTOF_2 0x79
#define RAM_ROLAVG_SUMTOF_3 0x7A
#define RAM_ROLAVG_SUMTOF_4 0x7B
#define RAM_ROLAVG_SUMTOF_5 0x7C
#define RAM_ROLAVG_SUMTOF_6 0x7D
#define RAM_ROLAVG_SUMTOF_7 0x7E
#define RAM_ROLAVG_SUMTOF_FIL 0x7F

//--------------  RAM Frontend Data Buffer 0x80 - 0x9B 128 - 155   -------------------------------
#define FDB 0x80 //---- Frontend Data Buffer

#define FDB_US_TOF_ADD_ALL_U 0x80 // 128---- TOF Sum Up of all the configured hits
#define FDB_US_TOF_ADD_ALL_D 0x84 // 132---- TOF Sum Down of all the configured hits
#define FDB_US_AM_U 0x82		  //---- US Amplitude Value Up
#define FDB_US_AM_D 0x86		  //---- US Amplitude Value Down
#define FDB_US_AMC_VH 0x83		  //---- US Amplitude Calibrate Value High
#define FDB_US_AMC_VL 0x87		  //---- US Amplitude Calibrate Value Low
#define FDB_US_PW_U 0x81		  //---- US Pulse Width Ratio Up
#define FDB_US_PW_D 0x85		  //---- US Pulse Width Ratio Down
#define FDB_US_TOF_0_U 0x88		  //---- Ultrasonic TOF Up Value 0	// added in A1.A1.22.01
#define FDB_US_TOF_1_U 0x89		  //---- Ultrasonic TOF Up Value 1
#define FDB_US_TOF_2_U 0x8A		  //---- Ultrasonic TOF Up Value 2
#define FDB_US_TOF_3_U 0x8B		  //---- Ultrasonic TOF Up Value 3
#define FDB_US_TOF_4_U 0x8C		  //---- Ultrasonic TOF Up Value 4
#define FDB_US_TOF_5_U 0x8D		  //---- Ultrasonic TOF Up Value 5
#define FDB_US_TOF_6_U 0x8E		  //---- Ultrasonic TOF Up Value 6
#define FDB_US_TOF_7_U 0x8F		  //---- Ultrasonic TOF Up Value 7
#define FDB_US_TOF_0_D 0x90		  //---- Ultrasonic TOF Down Value 0	// added in A1.A1.22.01
#define FDB_US_TOF_1_D 0x91		  //---- Ultrasonic TOF Down Value 1
#define FDB_US_TOF_2_D 0x92		  //---- Ultrasonic TOF Down Value 2
#define FDB_US_TOF_3_D 0x93		  //---- Ultrasonic TOF Down Value 3
#define FDB_US_TOF_4_D 0x94		  //---- Ultrasonic TOF Down Value 4
#define FDB_US_TOF_5_D 0x95		  //---- Ultrasonic TOF Down Value 5
#define FDB_US_TOF_6_D 0x96		  //---- Ultrasonic TOF Down Value 6
#define FDB_US_TOF_7_D 0x97		  //---- Ultrasonic TOF Down Value 7

//-- Frontend Data Buffer for Temperature Measurement
#define FDB_TM_PP_M1 0x80	   // 128----tpp	Offset delay compensation value from Measurement 1
#define FDB_TM_PTR_RAB_M1 0x81 //----tRAB	Reference Impedance value from Measurement1
#define FDB_TM_PTC_CAB_M1 0x82 //----tCAB	PT Cold Impedance value Measurement1
#define FDB_TM_PTH_HAB_M1 0x83 //----tHAB	PT Hot Impedance value Measurement1
#define FDB_TM_PTR_RA_M1 0x84  // 132----tRA	1st Offset resistance value from Measurement1

#define FDB_TM_PP_M2 0x85	   //----tpp	 Offset delay compensation value from Measurement 2
#define FDB_TM_PTR_RAB_M2 0x86 //----tRAB	 Reference Impedance value from Measurement2
#define FDB_TM_PTC_CAB_M2 0x87 //----tCAB	 PT Cold Impedance value Measurement2
#define FDB_TM_PTH_HAB_M2 0x88 //----tHAB	 PT Hot Impedance value Measurement2
#define FDB_TM_PTR_RA_M2 0x89  //----tRA	 1st Offset resistance value from Measurement2

#define FDB_TM_PTR_4W_RB_M1 0x8A //----tRB	Reference 2nd Offset resistance value from Measurement1
#define FDB_TM_PTC_4W_CA_M1 0x8B //----tCA	PT Cold 1st Offset resistance value from Measurement1
#define FDB_TM_PTC_4W_CB_M1 0x8C //----tCB	PT Cold 2nd Offset resistance value from Measurement1
#define FDB_TM_PTC_4W_AC_M1 0x8D //----tAC	PT Cold 3rd Offset resistance value from Measurement1
#define FDB_TM_PTC_4W_BC_M1 0x8E //----tBC	PT Cold 4th Offset resistance value from Measurement1
#define FDB_TM_PTH_4W_HA_M1 0x8F //----tHA	PT Hot  1st Offset resistance value from Measurement1
#define FDB_TM_PTH_4W_HB_M1 0x90 //----tHB	PT Hot  2nd Offset resistance value from Measurement1
#define FDB_TM_PTH_4W_AH_M1 0x91 //----tAH	PT Hot  3rd Offset resistance value from Measurement1
#define FDB_TM_PTH_4W_BH_M1 0x92 //----tBH	PT Hot  4th Offset resistance value from Measurement1

#define FDB_TM_PTR_4W_RB_M2 0x93 //----tRB 	Reference 2nd Offset resistance value from Measurement2
#define FDB_TM_PTC_4W_CA_M2 0x94 //----tCA 	PT Cold 1st Offset resistance value from Measurement2
#define FDB_TM_PTC_4W_CB_M2 0x95 //----tCB 	PT Cold 2nd Offset resistance value from Measurement2
#define FDB_TM_PTC_4W_AC_M2 0x96 //----tAC 	PT Cold 3rd Offset resistance value from Measurement2
#define FDB_TM_PTC_4W_BC_M2 0x97 //----tBC 	PT Cold 4th Offset resistance value from Measurement2
#define FDB_TM_PTH_4W_HA_M2 0x98 //----tHA 	PT Hot  1st Offset resistance value from Measurement2
#define FDB_TM_PTH_4W_HB_M2 0x99 //----tHB 	PT Hot  2nd Offset resistance value from Measurement2
#define FDB_TM_PTH_4W_AH_M2 0x9A //----tAH 	PT Hot  3rd Offset resistance value from Measurement2
#define FDB_TM_PTH_4W_BH_M2 0x9B //----tBH 	PT Hot  4th Offset resistance value from Measurement2

// Temporary parameters and results in RAM cells used by firmware and/or ROM
// #############################################################################
//--------------Temporary RAM used in flow calculation (0x9C - 0xAF)-----------------
#define RAM_R_VA3_CURRENT_THETA 0xA3 //---- Temporary variable used to store the current temperature THETA
#define RAM_R_VA4_FLOWVAR_2 0xA4	 //---- Temporary variable used in flow calculation
#define RAM_R_VA5_FLOWVAR_1 0xA5	 //---- Temporary variable used in flow calculation
#define RAM_R_VA5_TOF_TO_FLT_U 0xA5	 //---- Normalised TOF Up value before filtering
#define RAM_R_VA6_TOF_TO_FLT_D 0xA6	 //---- Normalised TOF Down value before filtering

#define RAM_VA2_COEFF_k3 0xA2		  //---- Temporarily storing coefficient k3 from FWD memory
#define RAM_VA3_FHL_ADJ 0xA3		  //---- Temporary variable used in First Hit Level Adjustment to store the FWD_PW_DEV
#define RAM_R_VA3_FLOW_CALC_VAR2 0xA3 //---- Temporary variable used to store temperature T2
#define RAM_R_VA4_FLOW_CALC_VAR1 0xA4 //---- Temporary variable used to store temperature T1
#define RAM_R_VA5_COEFF_k1_AT_T2 0xA5 //---- Temporarily storing coefficient k1 at T2
#define RAM_R_VA6_COEFF_k2_AT_T2 0xA6 //---- Temporarily storing coefficient k2 at T2
#define RAM_R_VA7_COEFF_k3_AT_T2 0xA7 //---- Temporarily storing coefficient k3 at T2
#define RAM_VA8_COEFF_k1 0xA8		  //---- Temporarily storing coefficient k1 from FWD memory
#define RAM_VA9_COEFF_k2 0xA9		  //---- Temporarily storing coefficient k2 from FWD memory
#define RAM_R_VA9_AMC_DIFF 0xA9		  //---- Temporary variable used during gradient and offset evaluation

#define RAM_R_VA2_PWL_T1 0xA2  //---- lower temperature of the calibration rectangle
#define RAM_R_VA3_PWL_T2 0xA3  //---- upper temperature of the calibration rectangle
#define RAM_R_VA4_PWL_D1 0xA4  //---- lower DIFTOF of the calibration rectangle
#define RAM_R_VA5_PWL_D2 0xA5  //---- upper DIFTOF of the calibration rectangle
#define RAM_R_VA6_PWL_C11 0xA6 //---- PWL coefficient for T1 and D1
#define RAM_R_VA7_PWL_C21 0xA7 //---- PWL coefficient for T2 and D1
#define RAM_R_VA8_PWL_C12 0xA8 //---- PWL coefficient for T1 and D2
#define RAM_R_VA9_PWL_C22 0xA9 //---- PWL coefficient for T2 and D2
#define RAM_R_VAA_PWL_DT 0xAA  //---- TOF DIFF input value (formatted&scaled RAM_TOF_DIFF ?)

#define RAM_V9C_FLOW_CALC 0x9C		   //---- Temporary variable used in the Flow calculation routine
#define RAM_R_V9D_THETA_FOR_CALC 0x9D  //---- Temperature calculated on the basis of the measured temperature THETA, based on where it lies in our known range.
#define RAM_R_V9E_MEAS_RATE_INV 0x9E   //---- Inverse of the calculated measurement rate
#define RAM_VA0_CORR_ZERO_OS_T1 0xA0   //---- ZERO_OFFSET with non linear correction at temperature T1
#define RAM_VA1_CORR_ZERO_OS_T2 0xA1   //---- ZERO_OFFSET with non linear correction at temperature T2
#define RAM_R_VA2_FLOW_LPH_TO_FLT 0xA2 //---- Averaged Flow value after first stage filtering, input to second stage rolling average filter
#define RAM_VA4_SCL_FLOW_LPH 0xA4	   //---- Flow in lph scaled with maximum flow (nearest 2^n) with fd 24

#define RAM_R_VA7_TOF_SUM_IN_ROM 0xA7 //---- Temporary variable used to store the TOF_SUM value got from firmware
#define RAM_R_VA8_FHL_USER 0xA8		  //---- Temporary variable used in FHL_ADJ routine to store User defined Reliable First Hit Level
#define RAM_R_VA9_TOF_SUM_DELTA 0xA9  //---- Temporary variable used in FHL_ADJ routine to store User defined Expected change in TOF_SUM between successive hits
#define RAM_R_VAA_ZERO_OFFSET 0xAA	  //---- Quasi temporary in flow routine: From Calib Zero flow offset at Calibration temperature CALIB_THETA_O
#define RAM_R_VAB_F_SLOPE 0xAB		  //---- Quasi temporary in flow routine: From Calib Slope for linear correction of CONSTANT_F over THETA
#define RAM_R_VAC_F_OFFSET_HSC 0xAC	  //---- Quasi temporary in flow routine: F_OFFSET corrected with HS Clock calibration factor chosen w.r.t. THETA, for linear correction of CONST_F
#define RAM_R_VAD_CALIB_THETA_F 0xAD  //---- Quasi temporary in flow routine: From Calib Calibration temperature of CONSTANT_F
#define RAM_R_VAE_O_SLOPE 0xAE		  //---- Quasi temporary in flow routine: From Calib Slope for linear correction of ZERO_OFFSET over THETA
#define RAM_R_VAF_CALIB_THETA_O 0xAF  //---- Quasi temporary in flow routine: From Calib Calibration temperature of ZERO_OFFSET

#define RAM_R_VAD_T1 0xAD //---- Start temperature of the range used to select the coefficients
#define RAM_R_VAE_T2 0xAE //---- End temperature of the range used to select the coefficients

//------- RAM 0xAC - 0xAE used by ROM routine only in TEST_MODE_FHL---------
#define RAM_R_VAC_TOF_SUM_CALC 0xAC //---- TOF_SUM value calculated with given TOF_SUM_DELTA and measured TOF_SUM, used in TEST_MODE_FHL
#define RAM_R_VAD_LOW_LIM 0xAD		//---- Lower limit of interval, in the interval search method used in TEST_MODE_FHL
#define RAM_R_VAE_UP_LIM 0xAE		//---- Upper limit of interval, in the interval search method used in TEST_MODE_FHL

//-----------------------------  Temporary storage for RAM_R_FW_STATUS at start of FW ----------------
#define RAM_V9C_TEMP_STATUS 0x9C //---- Temporary variable used at beginning of firmware// change of A1.A1.22.01

//-----------------------------  Temperature measurement : RAM Variables for 2- or 4- Wire Mode----------------------------------------
#define RAM_V9C_CRATIO 0x9C		   //---- PT Cold ratio = (PTC_RES/REF_RES_VAL)  * (FWD_PTC_RATIO_INV) with fd 16
#define RAM_V9D_HRATIO 0x9D		   //---- PT Hot ratio = (PTH_RES/REF_RES_VAL) * (FWD_PTH_RATIO_INV) with fd 16
#define RAM_V9E_COLD_VAL1 0x9E	   //---- Cold Intermediate Value 1, for calculating Cold Lower Offset Resistance
#define RAM_V9F_COLD_VAL2 0x9F	   //---- Cold Intermediate Value 2, for calculating Cold Lower Offset Resistance
#define RAM_VA0_COLD_VAL3 0xA0	   //---- Cold Intermediate Value 3, for calculating Cold Lower Offset Resistance
#define RAM_VA1_COLD_VAL4 0xA1	   //---- Cold Intermediate Value 4, for calculating Cold Lower Offset Resistance
#define RAM_VA2_COLD_VAL5 0xA2	   //---- Cold Intermediate Value 5, for calculating Cold Lower Offset Resistance
#define RAM_VA3_COLD_VAL6 0xA3	   //---- Cold Intermediate Value 6, for calculating Cold Lower Offset Resistance
#define RAM_VA4_HOT_VAL1 0xA4	   //---- Hot Intermediate Value 1, for calculating Hot Lower Offset Resistance
#define RAM_VA5_HOT_VAL2 0xA5	   //---- Hot Intermediate Value 2, for calculating Hot Lower Offset Resistance
#define RAM_VA6_HOT_VAL3 0xA6	   //---- Hot Intermediate Value 3, for calculating Hot Lower Offset Resistance
#define RAM_VA7_HOT_VAL4 0xA7	   //---- Hot Intermediate Value 4, for calculating Hot Lower Offset Resistance
#define RAM_VA8_HOT_VAL5 0xA8	   //---- Hot Intermediate Value 5, for calculating Hot Lower Offset Resistance
#define RAM_VA9_HOT_VAL6 0xA9	   //---- Hot Intermediate Value 6, for calculating Hot Lower Offset Resistanc
#define RAM_VAA_TM_VAR1 0xAA	   //---- Temporary variable used during Temperature Measurement evaluation
#define RAM_VAB_TM_VAR2 0xAB	   //---- Temporary variable used during Temperature Measurement evaluation
#define RAM_VAC_TM_VAR3 0xAC	   //---- Temporary variable used during Temperature Measurement evaluation
#define RAM_VAD_TM_VAR4 0xAD	   //---- Temporary variable used during Temperature Measurement evaluation
#define RAM_R_VAE_TM1 0xAE		   //---- Temporary variable used to store intermediate values during Temperature Measurement
#define RAM_R_VAF_TM2 0xAF		   //---- Temporary variable used to store intermediate values during Temperature Measurement
#define RAM_R_VAF_REF_RES_VAL 0xAF //---- The reference resistor value (internal / external) with fd 16

//----  RAM Probe Data ( 0x4B - 0x51 ) ----------------------------- UART Test only
#define RAM_VA0_PRB_DATA 0xA0		  //---- Start Probe Data
#define RAM_R_VA0_UART_PRB_DATA1 0xA0 //---- Data 1 to be sent through the UART
#define RAM_R_VA1_UART_PRB_DATA2 0xA1 //---- Data 2 to be sent through the UART
#define RAM_R_VA2_UART_PRB_DATA3 0xA2 //---- Data 3 to be sent through the UART
#define RAM_R_VA3_UART_PRB_DATA4 0xA3 //---- Data 4 to be sent through the UART
#define RAM_R_VA4_UART_PRB_DATA5 0xA4 //---- Data 5 to be sent through the UART
#define RAM_R_VA5_UART_PRB_DATA6 0xA5 //---- Data 6 to be sent through the UART
#define RAM_R_VA6_UART_PRB_DATA7 0xA6 //---- Data 7 to be sent through the UART

// ----Temporary RAM used to get data read through the I2C -----------------I2C Test only
// #define RAM_DWORD_FROM_EEPROM	0xA2			//---- Data read back from the EEPROM
#define RAM_R_VA1_I2CADDR 0xA1 //---- Temporary variable used in the I2C routine to store the destination address
#define RAM_R_VA2_I2CDATA 0xA2 //---- Temporary variable used in the I2C routine to store the data

//--------------0xA8 to 0xAF is used for temporary variables in HG's ROM codes
#define RAM_R_VAB_FWA_CS 0xAB  //---- FWA CHECKSUM
#define RAM_R_VAA_FWU_CS 0xAA  //---- FWU CHECKSUM
#define RAM_R_VA9_FWD2_CS 0xA9 //---- FWD2 CHECKSUM
#define RAM_R_VA8_FWD1_CS 0xA8 //---- FWD1 CHECKSUM
#define RAM_R_VAF_FWA_REV 0xAF //---- Firmware Code Revision
#define RAM_R_VAE_FWU_REV 0xAE //---- Firmware Code Revision

//-----------------------------FIRMWARE DATA MEMORY : x100 - 0x16B--------------------------------------
// Range for regular operation data backup : 0x100 - 0x11F
// not used by acam FW : 0x100 ....... 0x10F, 0x110...0x129 if PWL is not used
// used by ROM by design// 0x16C - 0x17F
// used by general ROM routines: any named FWD_R_...
// used by acam FW temperature measurement: 0x160-0x16A
// used by acam FW flow operation and quality control: 0x14E...1x15F
// used by acam FW flow calculation including calibration: 0x110...0x129 (only PWL),0x12A...0x14D
// used by acam FW flow temperature calculation: 0x160...0x169

//---------------- alternative: Data for backup in NVRAM
#define FWD_R_FLOW_VOLUME_INT 0x100		 // 000---- Integer part of Total volume of water flow in Cubic meter // used temporarily for Negative limit // change of A1.A1.22.01
#define FWD_R_FLOW_VOLUME_FRACTION 0x101 // 001---- Fractional part of Total volume of water flow in Cubic meter // used temporarily for Negative limit // change of A1.A1.22.01
#define FWD_R_FLOW_LPH 0x102			 // 002---- Calculated flow volume (l/h) with fd 16 without filtering
// reuse of some unused addresses, see below// change of A1.A1.22.01
// #define FWD_R_FILTERED_FLOW_LPH		0x103			//003---- Filtered flow volume (l/h) with fd 16
#define FWD_R_THETA 0x104 // 004---- Calculated Temperature with 16 fd (°C)// take care, is used in ROM by ROM_SEND1_UART_PRB_DATA
// #define FWD_R_SOUND_VEL				0x105			//005---- Velocity of sound with 8 fd(m/s)

// #define FWD_R_FLOW_SPEED			0x106			//006---- Calculated speed of flow (m/s) with fd 16

#define FWD_R_TOF_DIFF 0x107	  // 007---- TOF Difference
#define FWD_R_TOF_SUM 0x108		  // 008---- TOF Sum
#define FWD_R_VOLUME_FACTOR 0x109 // 009---- Fixed factor for multiplication during calculation of Flow Volume in Cubic meter
#define FWD_R_VCAL_TYP 0x10A	  // 010---- alternative typical amplitude value

//---------------- optional: Average error counters// change of A1.A1.22.01
#define FWD_ERROR_COUNT_CONF1 0x103 // 003---- Configure Error counter 1: Set errors to be counted according to bits in RAM_R_FW_ERR_FLAGS
#define FWD_ERROR_COUNT_CONF2 0x104 // 004---- Configure Error counter 2: Set errors to be counted according to bits in RAM_R_FW_ERR_FLAGS
#define FWD_ERROR_COUNT_21 0x105	// 005---- B1,B0: Count of errors within last hour configured by FWD_ERROR_COUNT_CONF1// B3,2 the same for ...CONF2// reset every hour by recall
#define FWD_ERROR_COUNT_43 0x106	// 006---- B1,B0: Count of any errors within last hour// B3,2 count of hardware error flags within last hour// reset every hour by recall

//----------------- Firmware Data memory	for flow calculation
// alternative: PWL/general calibration coefficients table
#define FWD_COEFF_ORG 0x110 // 016-----table organisation register, defines temperatures, DIFTOFS and coefficient blocks
#define FWD_COEFF_01 0x111	// 017---- Coefficients register 01
#define FWD_COEFF_02 0x112	// 018---- Coefficients register 02
#define FWD_COEFF_03 0x113	// 019---- Coefficients register 03
#define FWD_COEFF_04 0x114	// 020---- Coefficients register 04
#define FWD_COEFF_05 0x115	// 021---- Coefficients register 05
#define FWD_COEFF_06 0x116	// 022---- Coefficients register 06
#define FWD_COEFF_07 0x117	// 023---- Coefficients register 07
#define FWD_COEFF_08 0x118	// 024---- Coefficients register 08
#define FWD_COEFF_09 0x119	// 025---- Coefficients register 09
#define FWD_COEFF_10 0x11A	// 026---- Coefficients register 10
#define FWD_COEFF_11 0x11B	// 027---- Coefficients register 11
#define FWD_COEFF_12 0x11C	// 028---- Coefficients register 12
#define FWD_COEFF_13 0x11D	// 029---- Coefficients register 13
#define FWD_COEFF_14 0x11E	// 030---- Coefficients register 14
#define FWD_COEFF_15 0x11F	// 031---- Coefficients register 15
#define FWD_COEFF_16 0x120	// 032---- Coefficients register 16
#define FWD_COEFF_17 0x121	// 033---- Coefficients register 17
#define FWD_COEFF_18 0x122	// 034---- Coefficients register 18
#define FWD_COEFF_19 0x123	// 035---- Coefficients register 19
#define FWD_COEFF_20 0x124	// 036---- Coefficients register 20
#define FWD_COEFF_21 0x125	// 037---- Coefficients register 21
#define FWD_COEFF_22 0x126	// 038---- Coefficients register 22
#define FWD_COEFF_23 0x127	// 039---- Coefficients register 23
#define FWD_COEFF_24 0x128	// 040---- Coefficients register 24
#define FWD_COEFF_25 0x129	// 041---- Coefficients register 25

// acam nonlinear calibration table (temperatures also used for linear calibration)
#define FWD_R_COEFF_k1_TC1 0x12A // 042---- From Calibration : Coefficient k1 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k2_TC1 0x12B // 043---- From Calibration : Coefficient k2 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k3_TC1 0x12C // 044---- From Calibration : Coefficient k3 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k1_TC2 0x12D // 045---- From Calibration : Coefficient k1 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k2_TC2 0x12E // 046---- From Calibration : Coefficient k2 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k3_TC2 0x12F // 047---- From Calibration : Coefficient k3 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k1_TC3 0x130 // 048---- From Calibration : Coefficient k1 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k2_TC3 0x131 // 049---- From Calibration : Coefficient k2 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k3_TC3 0x132 // 050---- From Calibration : Coefficient k3 at temperature TC1 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k1_TC4 0x133 // 051---- From Calibration : Coefficient k1 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k2_TC4 0x134 // 052---- From Calibration : Coefficient k2 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_COEFF_k3_TC4 0x135 // 053---- From Calibration : Coefficient k3 at temperature TC2 for non-linear correction of ZERO_OFFSET over TOF_DIFF
#define FWD_R_TEMP_TC1 0x136	 // 054---- From Calibration : First Calibration temperature of non-linear correction coefficients k1, k2 and k3
#define FWD_R_TEMP_TC2 0x137	 // 055---- From Calibration : Second Calibration temperature of non-linear correction coefficients k1, k2 and k3
#define FWD_R_TEMP_TC3 0x138	 // 056---- From Calibration : Third Calibration temperature of non-linear correction coefficients k1, k2 and k3
#define FWD_R_TEMP_TC4 0x139	 // 057---- From Calibration : Fourth Calibration temperature of non-linear correction coefficients k1, k2 and k3

// parameters for acam nonlinear calibration
#define FWD_R_TOF_OFFSET 0x13A	 // 058---- From Calibration : TOF Offset to be deducted from the TOF_ADD_ALL
#define FWD_TOF_DIFF_CAL 0x13B	 // 059---- From Calibration : DIFF TOF value at calibration point
#define FWD_DIST_WITH_FLOW 0x13C // 060---- From Calibration : Measuring distance with flow
#define FWD_DIST_NO_FLOW 0x13D	 // 061---- From Calibration : Measuring distance with no flow

// parameters for linear calibration
#define FWD_R_ZERO_OFFSET_TC2 0x13E // 062---- From Calibration : Zero flow offset at calibration temperature TC2
#define FWD_R_ZERO_OFFSET_TC3 0x13F // 063---- From Calibration : Zero flow offset at calibration temperature TC3
#define FWD_R_ZERO_OFFSET_TC4 0x140 // 064---- From Calibration : Zero flow offset at calibration temperature TC4
#define FWD_R_O_SLOPE_TC12 0x141	// 065---- From Calibration : Slope for linear correction of ZERO_OFFSET over THETA in range TC1 - TC2
#define FWD_R_O_SLOPE_TC23 0x142	// 066---- From Calibration : Slope for linear correction of ZERO_OFFSET over THETA in range TC2 - TC3
#define FWD_R_O_SLOPE_TC34 0x143	// 067---- From Calibration : Slope for linear correction of ZERO_OFFSET over THETA in range TC3 - TC4
#define FWD_R_F_SLOPE_TC12 0x144	// 068---- From Calibration : Slope for linear correction of CONST_F over THETA in range TC1 - TC2
#define FWD_R_F_SLOPE_TC23 0x145	// 069---- From Calibration : Slope for linear correction of CONST_F over THETA in range TC2 - TC3
#define FWD_R_F_SLOPE_TC34 0x146	// 070---- From Calibration : Slope for linear correction of CONST_F over THETA in range TC3 - TC4
#define FWD_R_F_OFFSET_TC2 0x147	// 071---- From Calibration : Offset for linear correction of CONSTANT_F over THETA in range TC1 - TC2
#define FWD_R_F_OFFSET_TC3 0x148	// 072---- From Calibration : Offset for linear correction of CONSTANT_F over THETA in range TC2 - TC3
#define FWD_R_F_OFFSET_TC4 0x149	// 073---- From Calibration : Offset for linear correction of CONSTANT_F over THETA in range TC3 - TC4

// parameters for calculation of temperature from flow
#define FWD_SOUND_VEL_MAX 0x14A // 074---- From Calibration : Velocity of sound at Max. flow
#define FWD_1_BY_A 0x14B		// 075---- From Calibration : constant
#define FWD_CONST_C 0x14C		// 076---- From Calibration : constant
#define FWD_THETA_MAX 0x14D		// 077---- From Calibration : 74°C

// parameters for flow measurement quality control
#define FWD_LONG_TERM_ERROR 0x14E // 078---- Number of faulty measurements to conclude a long term error condition
#define FWD_FHL_USER 0x14F		  // 079---- User defined Reliable First Hit Level in 0.88mV fd0,or ratio to amplitude fd16/0.88mV// for constant burst length mode, set to zero
#define FWD_TOF_SUM_DELTA 0x150	  // 080---- User defined Expected change in TOF_SUM between successive hits (Raw value)
#define FWD_TOFSUM_VAR_LIM 0x151  // 081---- Allowed variation in the TOF_SUM between consecutive measurements (Raw value)
#define FWD_HSC_DEV 0x152		  // 082---- Firmware data memory with maximum permissible deviation in the HS clock from 4 LS clock periods(250 or 125 ns) * 2^16
// #define FWD_R_AMC_AVG_FACTOR			0x153			//083---- Number of Amplitude Calibration values to be averaged, only 2^N values possible // replaced by error flag vector// change of A1.A1.22.01
#define FWD_ERR_INTERRUPT 0x153 // 083---- error flag vector: set bits to decide which error flag should issue an interrupt// bits are identical to RAM_R_FW_ERR_FLAGS// change of A1.A1.22.01
#define FWD_AM_DIFF_LIM 0x154	// 084---- Firmware data memory with maximum permissible Up-Down Amplitude difference
#define FWD_R_AM_MIN 0x155		// 085---- Firmware data memory with minimum allowed amplitude value
#define FWD_PW_NOM 0x156		// 086---- Firmware data memory with Nominal value of PWR (*2^8)
#define FWD_PW_DEV 0x157		// 087---- Firmware data memory with allowed Deviation between up and down value (*2^8)
#define FWD_TEST_CONFIG 0x158	// 088---- Configuration for FHL test mode, depending on FHL regulation mode // change of A1.A1.22.01

// parameters for flow measurement operation control
#define FWD_TOF_RATE_FACTOR 0x159	// 089---- Factor for scaling the TOF rate and reducing the TOF measurement rate in case of zero flow (2^N value only)
#define FWD_FLOW_AVG_FACTOR 0x15A	// 090---- Number of flow values to be sampled for simple averaging
#define FWD_R_PULSE_PER_LITER 0x15B // 091---- Firmware data memory with the number of pulses per litres for the Pulse Interface
#define FWD_R_PULSE_MAX_FLOW 0x15C	// 092---- Firmware data memory with the maximum flow in litres
#define FWD_R_FHL_VALUE 0x15D		// 093---- Value for the first hit level, specific to the transducer - for ROM_FWI routine, to make it obsolete overwrite immediately ! xxx change in new ROM
#define FWD_NEG_FLOW_LIMIT 0x15D	// 093---- New usage: Negative flow ignore limit // change of A1.A1.22.01
#define FWD_R_TOF_DIFF_LIMIT 0x15E	// 094---- Minimum Limit for TOF_DIFF value
#define FWD_ZERO_FLOW_LIMIT 0x15F	// 095---- Limit in Litre Per Hour (LPH) that is detected as Zero Flow by the system * 2^16

//----------------- Firmware Data memory for temperature measurement
#define FWD_CAL_PTR_OFFSETR 0x160 // 096---- Calibration value for the Reference branch Offset Resistance for INTERNAL REFERENCE with fd 16
#define FWD_EXT_REF_VAL 0x161	  // 097---- Resistance value of the external reference resistor fd 16
#define FWD_PTC_SLOPE 0x162		  // 098---- PT Cold sensor resistance slope with fd 16
#define FWD_PTH_SLOPE 0x163		  // 099---- PT Hot sensor resistance slope with fd 16
#define FWD_PT_INT_SLOPE 0x164	  // 100---- Internal sensor resistance slope with fd 16
#define FWD_PTC_NOM 0x165		  // 101---- PT Cold sensor nominal resistance with fd 16
#define FWD_PTH_NOM 0x166		  // 102---- PT Hot sensor nominal resistance with fd 16
#define FWD_PT_INT_NOM 0x167	  // 103---- Internal sensor nominal resistance with fd 16
#define FWD_PTC_RATIO_INV 0x168	  // 104---- For PT Cold sensor : REF_RES_VAL / R0 of PT Cold with fd 16 // R0 is the PT Cold resistance at 0°C
#define FWD_PTH_RATIO_INV 0x169	  // 105---- For PT Hot sensor  : REF_RES_VAL / R0 of PT Hot with fd 16 // R0 is the PT Hot resistance at 0°C

// start address of PWL calibration data block
#define FWD_FW_CONFIG 0x16A // 106----FW configuration: see BNR definition below
// (initial) value of first hit level
#define FWD_R1_FHL_VALUE 0x16B // 107---- Value for the first hit level, specific to the transducer - corrected cell postition

// addresses that are hard coded by design, used by ROM codes
#define FWD_R_BD 0x100	// 000--Backup Data Data in FWD - start of 1st NVRAM block (end 0x11F), which can be backuped alone
#define FWD_R_ASD 0x120 // 032--Application Specific Data in FWD - reflects the hardware-limit between NVRAM blocks

#define FWD_R_CD 0x16C // 108----Configuration Data in FWD start// Don't write zero here, since the firmware uses this as indication for a recall
//... FWD input for configuration registers CR_...
#define FWD_USM_PRC 0x174 // 116----Configuration data for CR_USM_PRC, plus TOF_RATE added in B3// change of A1.A1.22.01
#define FWD_USM_FRC 0x175 // 117----Configuration data for CR_USM_FRC // add in A1.A1.22.01
#define FWD_USM_TOF 0x176 // 118----Configuration data for CR_USM_FRC // add in A1.A1.22.01

#define FWD_FW_RLS 0x17B // 123----Boot loader release
#define FWD_R_LAST 0x17B // 123----Configuration Data in FWD end

#define FWD_R_FWD1_CS 0x17C // 124----Checksum Firmware Data 1
#define FWD_R_FWD2_CS 0x17D // 125----Checksum Firmware Data 2
#define FWD_R_FWU_CS 0x17E	// 126----Checksum Firmware Code User
#define FWD_R_FWA_CS 0x17F	// 127----Checksum Firmware Code ACAM

//=================================================================================================================

// -------------------------------------------- constant Parameter definition----------------------------------
// #define CPU_TEST_OK					0x11111111		//---- CPU Test Ok
// #define CPU_TEST_ERR					0x2BAD2BAD		//---- CPU Test Failed
// #define HSC_CALIB_FAIL				0x0C0D0C0D		//---- HSC Calibration failed because deviation is out of range
#define FILTER_LEN_TOF 8	 //---- Length of the rolling average filter used for DIFF_TOF and SUM_TOF
#define FILTER_LEN_MEDIAN 5	 //---- For median filter - odd filter lengths only 5, 7, 9, 11 max.
#define FILTER_LEN_ROLLAV 16 //---- Length of the rolling average filter to filter the flow after normal averaging
//-- Temperature Measurement
#define PT_COEFF2 0x000A1D70 //----  10.115 * 2^16 Polynomial 2nd Order Coefficient for PT sensor
#define PT_COEFF1 0x00EB91EB //----  235.57 * 2^16 Polynomial 1st Order Coefficient for PT sensor
#define PT_COEFF0 0xFF0A5127 //---- -245.683 * 2^16 Polynomial constant for PT sensor

//============================ numerical constants ============================================
//-- Amplitude Measurement
#define AMC_R_VCAL_TYP 0x15E	//---- 350 mV typical cal amplitude (optional)
#define AMC_VLIM_DEFECT 0x10000 //---- 16mV fd16 typical amplitude to distinguish non water and hardware failure in test case

//================== Bit Numbers of Configuration registers (added in A1.A2.11.01) =====================================
#define BNR_TI_GM_MODE 26
#define BNR_TI_PATH_EN_3 24
#define BNR_TI_PATH_SEL_1 19
#define BNR_TI_PATH_SEL_0 18

//================== Bit Numbers of Firmware Status (RAM_R_FW_STATUS)=====================================
// Reorganising the RAM_R_FW_STATUS to match the bit numbers of SRR_FEP_STF

// The following 8 bit numbers are copied from SRR_FEP_STF registers' bits and contain the current state
// #define BNR_HSC_CLB_REQ			0 			//---- High Speed Clock Calibration Request
// #define BNR_TM_CALC_REQ			1			//---- Temperature Calculation Request

// #define BNR_AM_CLB_REQ			9			//---- AM Calibration Request
// #define BNR_AM_MON_REQ			8			//---- AM Monitor Request
// #define BNR_MEAS_FAILURE_ALERT	7			//---- TOF measurement edge=US_TOF_EDGE// Cleared in ROM_FWI routine under wrong name BNR_MEAS_FAILURE_ALERT//correction of A1.A1.22.01
// #define BNR_FLOW_CALC_REQ		6			//---- Flow Calculation Request
// #define BNR_FLOW_CALC_REQ		5			//---- Flow Calculation Request Down
// #define BNR_FLOW_CALC_REQ		4			//---- Flow Calculation Request Up

#define BNR_FWI_DONE 2			  //---- Firmware Init Done
#define BNR_FLOW_FILT_INIT_DONE 3 //---- Filter for Flow : initialization done

#define BNR_MEAS_FAILURE_ALERT 10 //---- 1: Indicates measurement fails too often (more than 4 times in a sequence)// change of A1.A1.22.01

#define BNR_FILTER_INIT_DONE 11 //---- Filter initialization done in the flow calc. routine
// #define BNR_CAL_METHOD			12			//---- Indicate if PWL (=1) or acam (=0) calibration// not used// change of A1.A1.22.01

#define BNR_UART_IF_ENABLED 13	  //---- This bit indicates if the UART interface is enabled or not
								  //	  to decide if data has to be sent out after post processing
#define BNR_AVG_TOF_FOR_FLOW 14	  //---- This bit is set when the TOF values are averaged over a particular number of
								  //	  meas. cycles before using it for flow calculation
#define BNR_TOFSUM_DIV_MODE 15	  //---- Division mode for dividing the TOF SUM
								  //---- 0 : Division by shifting, 1: Normal division
#define BNR_HSC_SCALE_EN 16		  //---- High Speed Clock Scaling Enable
#define BNR_PI_UPD_REQ 17		  //---- Pulse Interface Update Request
#define BNR_NON_ZERO_FLOW 18	  //---- 1: When current flow value lies considerable over the ZERO_FLOW_LIMIT, else 0
#define BNR_THETA_OUT_OF_RANGE 19 //---- 1: The current temperature lies outside the range between TC_LOW and TC_HIGH, else 0
#define BNR_NEW_VAL_IS_OUTLIER 20 //----Used in ROM routine
								  // 1: The newest value in the filter is the outlier and will be eliminated for average calculation
#define BNR_I2C_ABORT 21		  //----Used in ROM routine
								  // 1: When the I2C transaction is aborted because a NOT ACKNOWLEDGE is received for any byte sent
#define BNR_TEMP_REFRSH 22		  // 1: Indicates that the register must be restored after a recall action // change of A1.A1.22.01

#define BNR_PI_ERR_1ST_DIR 23	 //---- stores the direction port signal when starting error signalling// toggles to mutually cancel error pulses// change of A1.A2.11.01
#define BNR_TEST_MODE_ADJ 24	 //---- 1: Test Mode to adjust First Hit Level
#define BNR_TEST_MODE_EP 25		 //---- 1: Test Mode to determine empty pipe or hardware error
#define BNR_EN_FHL_MONITORING 26 //---- 1: Checks to monitor FHL (because of jumps in the TOF_SUM value and the Pulse width Ratios) are enabled// 0 : disabled
#define BNR_FHL_ADJ_REQ 27		 //---- 1: First Hit Level Adjustment in firmware requested
#define BNR_USER_DEFINED_FHL 28	 //----Used in ROM routine // 1 : Indicates that the User defined FHL is configured after a measurement failure.
#define BNR_TOF_RATE_REDUCED 29	 //----Used in ROM routine & firmware // 1: When the TOF rate is reduced in case of zero flow, 0 : Original configured TOF rate
#define BNR_TOF_DIFF_NEGATIVE 30 //---- 1: This bit is set when linearly corrected TOF_DIFF is negative
#define BNR_TEST_MODE_FHL 31	 //---- 1: Test Mode to control the First Hit Level or recover from an error state

//================== Bit Numbers of Firmware Error Flags (RAM_R_FW_ERR_FLAGS)=====================================

#define BNR_HS_CALIB_FAIL 0		//---- Used in ROM routine// HS Clock Calibration not performed because the deviation is too large
#define BNR_AMP_DIFF_TOO_HIGH 1 //---- Difference in the measured Amplitudes is out of range
#define BNR_AMP_VAL_TOO_LOW 2	//---- Used in ROM routine// Calculated Amplitude value is lower than the minimum
#define BNR_PW_DIFF_NOT_OK 3	//---- Pulse width Ratio difference is not O.K. // change of A1.A1.22.01
#define BNR_SUMTOF_DEV 4		//---- Current SUMTOF deviates too much from former values // change of A1.A1.22.01
#define BNR_FHL_NOT_OK 5		//---- Current FHLevel does not fulfill test criteria or is beyond limits // change of A1.A1.22.01
#define BNR_MEAS_NOT_OK 6		//---- 0: Measurement is OK  1: Measurement is NOT OK // change of A1.A1.22.01
// #define BNR_MEAS_FAILURE_ALERT		7		//---- 1: Measurement fails too often, indicates a hardware failure// moved to RAM_R_FW_STATUS as internal flag// change of A1.A2.11.01
#define BNR_HARDWARE_FAILURE 7 //---- 1: Hardware failure detected in a long term error condition// transducer short or open or Amplitude too low in long term// change of A1.A1.22.01
#define BNR_FLOW_BT_2MAX 8	   //---- 1: measured absolute FLOW is above 2 times the given maximum value// change of A1.A1.21.01
#define BNR_FLOW_LT_NEGLIM 9   //---- 1: measured absolute FLOW is below the negative limit// change of A1.A1.22.01
#define BNR_VOL_ERR 10		   //---- 1: Flow volume had an unrecoverable error// this bit is not cleared automatically// change of A1.A1.21.01
#define BNR_ROM_ERR 11		   //---- 1: ROM was called and did not return// usually happens when ROM has no power// this bit is not cleared automatically// change of A1.A1.22.01
#define BNR_ROM_TEMP_ERR 12	   //---- 1: Temporary error indicator to support identification of ROM functionality for BNR_ROM_ERR// change of A1.A1.22.01
#define BNR_VEL_ERROR 13	   //---- 1: currently calculated sound velocity is outside limits// change of A1.A1.22.01
#define BNR_BUBBLE 14		   //---- 1: Bubble concluded from 1,3 or 4 and RAM_R_FW_STATUS bit 7 //  change of A1.A1.22.01
#define BNR_NO_WATER 15		   //---- 1: No water concluded from 2 and long term error// change of A1.A1.22.01

// #define BNR_TRANSDUCER_SHORT			XX		//---- 1:  maybe to be introduced later (where ?) // change of A1.A1.22.01

// #define BNR...					31..16		//---- copies of bits 0..15 of SRR_ERR_FLG// change of A1.A1.22.01
#define BNR_TOF_TMO_FW 17 //---- TOF Timeout flag copied into RAM_R_FW_ERR_FLAGS
#define BNR_TSQ_TMO_FW 25 //---- Task Sequencer timeout flag copied into RAM_R_FW_ERR_FLAGS
//================== Bit Numbers of Firmware Config Flags (FWD_FW_CONFIG)=====================================

// Byte B0						7..0		//---- Start address of calibration data block for flexible definition (add leading 1 for full address)
// Byte B1						15..8		//---- scaling exponent for PWL coefficients: Multiply all coefficients by 2^B1

#define BNR_FWCONF_2MAX_NOZERO 16  //---- 0: flow will be set to 0 when BNR_FLOW_BT_2MAX is set// 1: Flow will remain in any case // change of A1.A2.11.01
#define BNR_FWCONF_FHL_ZEROFLOW 17 //---- 0: When FHL regulation is active, never assume zero flow// 1: FHL regulation has no influence on zero flow state

#define BNR_FWCONF_NO_PI_ERR 21 //---- 1: Never signal Error on PI// 0: Signal as configured below// change of A1.A2.11.01
#define BNR_FWCONF_PI_ERROR 22	//---- 1: Also Signal Empty pipe on pulse interface// 0: signal any long term error except empty pipe on PI // change of A1.A1.22.01
#define BNR_FWCONF_TESTMODE 23	//---- 1: Enter FHL test mode each two averaging cycles// 0: Enter FHL test mode only in case BNR_MEAS_FAILURE_ALERT// change of A1.A2.11.01
#define BNR_FWCONF_FHL0 24		//---- (depending on ...FHL1) 0: constant FHL or trusted FHL mode B// 1: trusted FHL mode A or receive path length// change of A1.A1.22.01
#define BNR_FWCONF_FHL1 25		//---- (depending on ...FHL0) 0: constant FHL or trusted FHL mode A// 1: trusted FHL mode B or receive path length// change of A1.A1.22.01
#define BNR_FWCONF_FHL_RATIO 26 //---- 1: User FHL is not constant value, but constant ratio to measured amplitude// change of A1.A1.22.01
#define BNR_FWCONF_VLIM 27		//---- 1: activate control of speed of sound limits// 0: no control // change of A1.A1.22.01
#define BNR_FWCONF_ERR 28		//---- 1: activate average error counters // 0: No average error counters // change of A1.A1.22.01
#define BNR_FWCONF_VOL 29		//---- 1: Apply volume storage protection// 0: No volume storage protection
#define BNR_FWCONF_TSENS 30		//---- 1: Use hot sensor temperature measurement// 0: use speed of sound temperature calculation
#define BNR_FWCONF_PWL 31		//---- 1: Use PWL calibration// 0: use acam calibration

//-----------------------------------------------------------------------------------------------------